/* Includes ------------------------------------------------------------------*/
#include "esp32.h"
#include "puresun_func.h"
#include "math.h"
#include <stdio.h>

/* Private macro -------------------------------------------------------------*/

/* Private typedef -----------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
 * Function Name : vaacum_init
 * Description   : vaacum init
 * Input         : [vaacum_t *vaacum, int baud, byte adr]
 *                 - vaacum: vaacum struct
 *                 - adr: vaacum address
 * Output        : None
 * Return        : None
 * Notes         : None
 * Attention	 : None
 *******************************************************************************/
void esp32_init(esp32_t *esp32, byte adr)
{
    // check vaacum
    if (esp32 == NULL)
        return;

    // check address
    if (adr < 0x01 || adr > 0x7F)
        return;

    // init vaacum
    esp32->adr = adr;            // device address
    esp32->value = 100 * 1000.0; // 100kPa
    esp32->digital = 10;         // 1.0
    esp32->pow = 5;              // E5
}

/*******************************************************************************
 * Function Name : vaacum_analyze
 * Description   : analyze vaacum data
 * Input         : [vaacum_t *vaacum, byte *frame_in, uint16_t datalen]
 *                 - vaacum: vaacum struct
 * Output        : None
 * Return        : None
 * Notes         : None
 * Attention	 : None
 *******************************************************************************/
void esp32_analyze(esp32_t *esp32)
{
    if (esp32 == NULL)
        return;
    for (int i = 0; i < 8; i++)
    {
        esp32->device_status_d[i] = (esp32->device_status_b & (0x01 << i)) == (0x01 << i) ? 1 : 0;
    }

    printf("\n");
}
/************************ (C) COPYRIGHT PURESUN **** END OF FILE ***************/
